<?php
namespace app\log\model;
use app\common\model\Common;
use think\Db;
class MsgLog extends Common
{
	protected $table = "mps_message_log";
	protected $autoWriteTimestamp = true;
	protected $createTime = 'addtime';
    protected $updateTime = false;
    protected $append = ['type_text'];

    /**
	 * 添加短信记录
	 */
	public function addMessageLog($info)
	{
		$data = [
			'repair_id'			=> $info['repair_id'],
			'message_id'		=> $info['message_id'],
			'content'			=> $info['content'],
			'type'				=> $info['type'],
			'addtime'			=> time(),
		];
		return $this->save($data);
	}
    /**
	 * 获取列表
	 * @param array $where 查询条件
	 * @param string $order 排序条件
	 * @param intger $page 当前页数
	 * @param intger $row 每页条数
	 * @param string $search 关键字检索条件
	 */
	public function listData($where, $order, $page, $row, $search = '')
	{
		if($row == 'limit'){
			$list = $this->where($search)->where($where)->order($order)->select();
		}else{
			$list = $this->where($search)->where($where)->order($order)->page($page, $row)->select();
		}
		return $list;
	}

	/**
	 * 获取器
	 */
    public function getTypeTextAttr($value,$data)
    {
    	switch($data['type']){
    		case 0: return '召回短信';break;
    		case 1: return '送机短信';break;
    		case 2: return '取消取机短信';break;
    		case 3: return '失败取机短信';break;
    		case 4: return '成功取机短信';break;
    		case 5: return '活动短信';break;
    		default: return '异常';break;
    	}
    }
}